export function base64toBlob(data) {
  const parts = data.split(";base64,"),
    contentType = parts[0].split(":")[1],
    raw = window.atob(parts[1]),
    length = raw.length,
    arr = new Uint8Array(length);
  for (let i = 0; i < length; i++) {
    arr[i] = raw.charCodeAt(i);
  }
  return new Blob([arr], { type: contentType });
}

export function blobToBase64(blob) {
  return new Promise((resolve) => {
    const reader = new FileReader();
    reader.readAsDataURL(blob);
    //读取后，result属性中将包含一个data:URL格式的Base64字符串用来表示所读取的文件
    reader.onload = function(e) {
      resolve(e.target);
    };
  });
}

export function fileToBase64(file) {
  return new Promise((resolve) => {
    let reader = new FileReader();
    reader.readAsDataURL(file);
    //读取后，result属性中将包含一个data:URL格式的Base64字符串用来表示所读取的文件
    reader.onload = function(e) {
      resolve(e.target.result);
    };
  });
}

export function fileToBlob(file) {
  return new Blob([file], { type: file.type });
}